<?php
namespace app\admin\controller;

use app\BaseController;
use app\common\controller\AdminController;
use think\App;
use think\facade\Session;
use think\facade\View;

class Index extends AdminController
{

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->menu = app('app\common\model\system\SystemMenu');
    }



    /**
     * 获取路由权限菜单
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View|mixed|\think\response\View
     */
    public function navigate()
    {
        //后台菜单
        $menus = $this->menu->with(['children'=>function($query){
            $query->where(['status'=>1,'type'=>1])->with(['children'=>function($query){
                $query->where(['status'=>1,'type'=>1])->select();
            }]);
        }
        ])->where(['pid'=>0,'status'=>1])->order('id','asc')->select()->toArray();

        $data = [
            'code' => 200 ,
            'msg' => '请求成功...' ,
            'data' => $menus ,
        ];
        return json($data);

    }

    /**
     * 首页数据
     * @return array|\Illuminate\Contracts\View\Factory|\Illuminate\View\View|mixed|\think\response\View
     */
   public function welcome()
   {
        $Integramodel = app('app\common\model\mall\IntegralItem');//积分商品
        $IntegralOrdermodel = app('app\common\model\mall\IntegralOrder');//积分商品订单

        $accountmodel = app('app\common\model\mall\Account');//课程表
        $ordermodel = app('app\common\model\mall\Order');//课程订单


        $admin = Session::get('admin');
        if($admin['store_id']!==0){
             $data['goods_count'] = $accountmodel->where('store_id',$admin['store_id'])->count();
             $data['goods_order'] = $ordermodel->where('store_id',$admin['store_id'])->count();
             $data['type'] = 2;
        }else{
            $data['goods_count'] = $Integramodel->where('app_id',$admin['app_id'])->count();
            $data['goods_order'] = $IntegralOrdermodel->where('app_id',$admin['app_id'])->count();
            $data['type'] = 1;
        }

        return view('',['data'=>$data]);
   }


}
